package com.hf.wujian.utils;

import com.hf.wujian.model.GameUser;
import redis.clients.jedis.Jedis;

import java.io.*;

public class RedisUtils {

    private static Jedis jedis;
//    static {
//         jedis = new Jedis("127.0.0.1");
//    }

    public static void addUser(GameUser gameUser){
        byte[] data = jedis.get(gameUser.getUuid().getBytes());
        if(data == null){

        }
//        System.out.println("value = " + jedis.get(gameUser.getUuid().getBytes()));
    }


    //序列化
    public static byte [] serialize(Object obj){
        ObjectOutputStream obi=null;
        ByteArrayOutputStream bai=null;
        try {
            bai=new ByteArrayOutputStream();
            obi=new ObjectOutputStream(bai);
            obi.writeObject(obj);
            byte[] byt=bai.toByteArray();
            return byt;
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    //反序列化
    public static Object unserizlize(byte[] byt){
        ObjectInputStream oii=null;
        ByteArrayInputStream bis=null;
        bis=new ByteArrayInputStream(byt);
        try {
            oii=new ObjectInputStream(bis);
            Object obj=oii.readObject();
            return obj;
        } catch (Exception e) {

            e.printStackTrace();
        }
        return null;
    }
}
